#!/bin/bash
set -e

here=$(cd `dirname $0` && pwd)
garden_root=$(cd ${here} && cd $(git rev-parse --show-toplevel) && pwd)
garden_bin="node ${garden_root}/garden-service/bin/garden"

cd ${garden_root}/examples/openfaas

export GARDEN_LOGGER_TYPE=basic

# make sure CLI returns with error when it should
set +e

${garden_bin} bla
if [[ $? -eq 0 ]]; then
  echo "Expected error when calling with bad command"
  exit 1
fi

${garden_bin} version
if [[ $? -ne 0 ]]; then
  echo "Expected exit code 0 when calling version"
  exit 1
fi

${garden_bin} --version
if [[ $? -ne 0 ]]; then
  echo "Expected exit code 0 when calling --version"
  exit 1
fi

${garden_bin} -v
if [[ $? -ne 0 ]]; then
  echo "Expected exit code 0 when calling -v"
  exit 1
fi

${garden_bin} help
if [[ $? -ne 0 ]]; then
  echo "Expected exit code 0 when calling help"
  exit 1
fi

${garden_bin} --help
if [[ $? -ne 0 ]]; then
  echo "Expected exit code 0 when calling --help"
  exit 1
fi

${garden_bin} -h
if [[ $? -ne 0 ]]; then
  echo "Expected exit code 0 when calling --help"
  exit 1
fi

set -e

${garden_bin} scan
${garden_bin} build
${garden_bin} deploy
${garden_bin} test
${garden_bin} init
